package org.ph.share.lock.test;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SynchronizedDemo1 {
    private int count = 0;

    public synchronized void increment() {
        count++;
    }

    public synchronized void decrement() {
        count--;
    }

    public synchronized int getCount() {
        return count;
    }

    public static void main(String[] args) {
        SynchronizedDemo1 demo = new SynchronizedDemo1();
        new Thread(() -> {
            demo.increment();
            log.info("demo.getCount():{}",demo.getCount());

        },"test-1").start();
        new Thread(() -> {
            demo.increment();
            log.info("demo.getCount():{}",demo.getCount());

        },"test-2").start();
    }
}
